package com.igeek.d0607;

import java.io.*;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @Author: zhiyu
 * @Date:16:35
 * @DESC:
 */
public class Test1 {
    static {
        System.out.println("com.igeek.d0607.Test1被加载了");
    }
    public static boolean login(){
        HashMap<String, String> userMap = new HashMap<>();
        Scanner scanner = new Scanner(System.in);
        try{
            InputStream resourceAsStream = Test1.class.getResourceAsStream("user.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
            String user = "";
            while ((user = br.readLine())!=null){
                String username = user.split("#")[0];
                String password = user.split("#")[1];
                userMap.put(username,password);
            }
            System.out.println("请输入你的用户名：");
            String name = scanner.nextLine();
            System.out.println("请输入你的密码:");
            String password = scanner.nextLine();
            for (String username: userMap.keySet()) {
               if (username.equals(name)){
                   if (password.equals(userMap.get(username))){
                       System.out.println("登陆成功");
                       return true;
                   }else {
                       System.out.println("密码输入错误");
                       return false;
                   }
               }
            }
            System.out.println("用户登陆失败");

        }catch (Exception e){
                 e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        login();
    }
}
